import request from "@/utils/request";

const BASE_URL = "/api/v1/process/";

const ProcessAPI = {
  getInfo(id: string) {
    return request<any, ProcessPageVO>({
      url: `${BASE_URL}${id}/`,
      method: "get",
    });
  },
  getPage(queryParams: ProcessPageQuery) {
    return request<any, PageResult<ProcessPageVO[]>>({
      url: `${BASE_URL}`,
      method: "get",
      params: queryParams,
    });
  },
  getFormData(id: string) {
    return request<any, ProcessForm>({
      url: `${BASE_URL}${id}/`,
      method: "get",
    });
  },
  add(data: ProcessForm) {
    return request({
      url: `${BASE_URL}`,
      method: "post",
      data: data,
    });
  },
  update(id: string, data: ProcessForm) {
    return request({
      url: `${BASE_URL}${id}/`,
      method: "patch",
      data: data,
    });
  },
  delete(id: string) {
    return request({
      url: `${BASE_URL}${id}/`,
      method: "delete",
    });
  },
  getOptions(query: string) {
    return request<any, OptionType[]>({
      url: `${BASE_URL}options/`,
      method: "get",
      params: { search: query },
    });
  },
};

export default ProcessAPI;

// Interfaces
// PageResult and PageQuery are assumed to be defined elsewhere in your project.
interface ProcessPageQuery extends PageQuery {
  /** 搜索关键字 */
  search?: string;
}

interface ProcessForm {
  id?: string;
  name?: string;
  title?: string;
  is_update?: boolean;
  status?: number;
}

interface ProcessPageVO {
  id: string;
  name: string;
  title: string;
  status: number;
  create_time?: Date;
  update_time?: Date;
  create_user?: string;
  update_user?: string;
}

export { ProcessPageVO, ProcessPageQuery, ProcessForm };
